package com.hmy.pig.controller;

import com.hmy.pig.domain.HmyPigBreed;
import com.hmy.pig.domain.HmyPigLive;
import com.hmy.pig.service.PigLiveService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import static com.ruoyi.common.core.utils.PageUtils.startPage;

/**
 * @author zhl
 * @descript 描述
 * @date 2024/2/1 12:44
 */
@RestController
@RequestMapping("/pigLive")
public class HmyPigLiveController extends BaseController {
    @Autowired
    private PigLiveService pigLiveService;

    /**
     * 查询进货信息列表
     *
     * @param pigCode      参数一：母猪耳号
     * @param pigLiveType  参数二：配种方式
     * @param pigLiveManager  参数二：配种负责人
     * @param dateStart 参数三：进货开始时间
     * @param dateEnd   参数四：进货结束时间
     * @return 返回查询列表
     */
    @RequiresPermissions("hmy:pigLive:list")
    @GetMapping("/list")
    public TableDataInfo list(String pigCode ,
                              Integer pigLiveType,
                              String pigLiveManager,
                              String dateStart,
                              String dateEnd)
    {
        startPage();
        List<HmyPigLive> list = pigLiveService.selectPigLiveList(pigCode,pigLiveType,pigLiveManager,dateStart,dateEnd);
        return getDataTable(list);
    }
    /**
     * @param hmyPigLive
     * @return com.ruoyi.common.core.web.domain.AjaxResult
     * @author ZHL
     * @date 2024/1/29 19:10
     * @description  新增猪只分娩记录
     */
    @RequiresPermissions("hmy:pigLive:add")
    @Log(title = "猪只分娩记录管理", businessType = BusinessType.INSERT)
    @PostMapping("add")
    public AjaxResult add(@RequestBody HmyPigLive hmyPigLive)
    {
        return toAjax(pigLiveService.insertPigLive(hmyPigLive));
    }
    /**
     * 根据pigBreedId获取单个分娩记录信息
     *
     * @param pigLiveId
     * @return
     */
    @RequiresPermissions("hmy:pigLive:query")
    @GetMapping("getInfo/{pigLiveId}")
    public AjaxResult selectPigLiveById(@PathVariable Long pigLiveId) {
        return AjaxResult.success(pigLiveService.selectPigLiveByPigLiveId(pigLiveId));
    }
    /**
     * 根据pigBreedId修改配种记录信息
     *
     * @param
     * @return
     */
    @PostMapping("update")
    @Log(title = "分娩记录管理", businessType = BusinessType.UPDATE)
    @RequiresPermissions("hmy:pigLive:update")
    public AjaxResult updatePigLive(@RequestBody HmyPigLive hmyPigLive) {
        return toAjax(pigLiveService.updatePigLive(hmyPigLive));

    }

    /**
     * 根据ID删除配种记录信息
     *
     * @param pigLiveIds
     * @return
     */
    @DeleteMapping("del/{pigLiveIds}")
    @RequiresPermissions("hmy:pigLived:del")
    public AjaxResult delPigLiveByPigLiveId(@PathVariable Long[] pigLiveIds) {
        return toAjax(pigLiveService.deletePigLiveByPigLiveIds(pigLiveIds));
    }

    @GetMapping("findAllStaffName")
    public AjaxResult findAllStaffName() {
        return AjaxResult.success(pigLiveService.findAllStaffName());
    }


}
